package opera1;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class DelOperation implements IOperation {
    @Override
    public void doWork(BookList bookList) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入你要删除的书名:");
        String delName = input.nextLine();
        for (int i = 0; i < bookList.getUsedSize(); i++) {
            Book book = bookList.getBook(i);
            if (book.getName().equals(delName)) {
                for (int j = i + 1; j < bookList.getUsedSize(); j++) {
                    Book book1 = bookList.getBook(j);
                    bookList.setBooks(i,book1);
                }
                break;
            }
        }
        bookList.setBooks(bookList.getUsedSize()-1,null);
        bookList.setUsedSize(bookList.getUsedSize()-1);
        System.out.println("删除成功!");
    }
}
